package com.tomtom.amelinium.backlogservice;

import java.util.ArrayList;

import com.tomtom.amelinium.backlogservice.builders.BacklogModelBuilder;
import com.tomtom.amelinium.backlogservice.corrector.BacklogModelCorrector;
import com.tomtom.amelinium.backlogservice.model.BacklogModel;
import com.tomtom.amelinium.backlogservice.serializer.BacklogModelSerializer;
import com.tomtom.amelinium.common.LineProducer;

public class BacklogServiceFactory {

	/**
	 * Reads backlog from file and builds the model.
	 */
	public BacklogModel readBacklogModel(String fileName) {
		
		LineProducer producer = new LineProducer();
		ArrayList<String> lines = producer.readLinesFromFile(fileName);
		BacklogModelBuilder builder = new BacklogModelBuilder();
		BacklogModel backlogModel = builder.buildBacklogModel(lines);
		
		return backlogModel;
	}
	
	/**
	 * Reads backlog from file, builds the model and recalculates the points.
	 */
	public BacklogModel readAndCorrectBacklogModel(String fileName) {
		
		BacklogModel backlogModel = readBacklogModel(fileName);
		BacklogModelCorrector backlogModelCorrector = new BacklogModelCorrector();
		
		return backlogModelCorrector.correctModelPoints(backlogModel);
	}
	
	/**
	 * Reads backlog from file, builds the model and recalculates the points.
	 */
	public String readCorrectAndSerializeModel(String fileName) {
		
		BacklogModel backlogModel = readAndCorrectBacklogModel(fileName);
		BacklogModelSerializer backlogModelSerializer=new BacklogModelSerializer();
		
		return backlogModelSerializer.serializeModel(backlogModel);
	}
	

}
